import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Main from '@/views/Main'
import Home from '@/views/home/Home'

import alarmRouter from './modules/alarm'
import warehouseRouter from './modules/warehouse'
import stockRouter from './modules/stock'
import reportRouter from './modules/report'
import deviceRouter from './modules/device'
import purchaseRouter from './modules/purchase'
import fundRouter from './modules/fund'
import wageAccountRouter from './modules/wageAccount'
import pickMangeRouter from './modules/pickMange'
import baseRouter from './modules/base'
import systemRouter from './modules/system'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  alarmRouter,
  warehouseRouter,
  stockRouter,
  reportRouter,
  deviceRouter,
  purchaseRouter,
  fundRouter,
  wageAccountRouter,
  pickMangeRouter,
  baseRouter,
  systemRouter,
  {
    path: '/main',
    component: Main,
    redirect: '/home',
    children: [{
        path: '/home',
        component: Home
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
